if (!this.keytemplate) {
	var keytemplate = {};
} 

keytemplate.callback=function(json){ 
	var templateKeyList = json.result;
		if (!templateKeyList)
			return;
	 
		$("[name^='KEY_']").each(function(e) {
			var keyContainer = $(this);
			var expectKey = $(this).attr('name').replace('KEY_', '');
			var templateName =  $(this).attr('templateName');
			var templateDataIndex = $(this).attr('templateDataIndex');
			for (var i = 0; i < templateKeyList.length; i++) {
				var group = templateKeyList[i];
				var groupKey = group.groupKey;
				if (expectKey == groupKey) {
					var defaultTemplateName = "keyTemplate";
					var loadData = group.blockList;
					if(!templateName)
						templateName = defaultTemplateName; 
					if(templateDataIndex && templateDataIndex < group.blockList.length )
						loadData = group.blockList[templateDataIndex];
					keyContainer.loadTemplate($("#"+templateName), loadData);
					break;
				}
			}
		}); 
		
 		var blockElementList = document.querySelectorAll("[blockid]");
		for (var i = 0; i < blockElementList.length; i++) {
			var url = blockElementList[i].getAttribute("blockurl"); 
			blockElementList[i].addEventListener('tap', function() {
				mui.openWindow({
					id: 'jumpPage',
					url: this.getAttribute("blockurl")
				});
			});
		}
};

 

keytemplate.initTemplateKey = function(templatePackageId,templateName,callBackFunctionName) {
	if(!callBackFunctionName)
		callBackFunctionName ="keytemplate.callback";
	
	var requestJson = {
		data: {
			templatePackageId:templatePackageId,
			templateName: templateName
		}
	};
	
	//ajax.jsonpSyncFetch("web/templateKey.op", requestJson, callBackFunctionName);
	ajax.syncJsonRequest({
		url: "index.json",
		success: function(data){ 
			  keytemplate.callback(data); 
		}
	});
};